package com.polaris.live.utils.route

import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import kotlin.reflect.KClass

/**
 * RouterManager
 *
 * @author Created by lucas on 2023/10/16 16:41
 */
object RouterManager {

    private val routers = RouterImpl.routers.associateBy { it.router }

    /**
     * 获取路由地址
     */
    fun getImpl(router: String): RouterAddress? {
        return routers[router]
    }
}

sealed class RouterAddress {

    abstract val router: String

    abstract val clazz: KClass<out AppCompatActivity>

}

class RouterAddressImpl(
    override val router: String,
    override val clazz: KClass<out AppCompatActivity>
) : RouterAddress()

class RouterAddressExecImpl(
    override val router: String,
    override val clazz: KClass<out AppCompatActivity>,
    val block: Context.(Intent) -> Boolean
) : RouterAddress()

infix fun String.nav(that: KClass<out AppCompatActivity>) = RouterAddressImpl(this, that)